using UnityEngine;
using System.Collections;

public class Menu_Text : MonoBehaviour
{
	GUIText menuItem;							//Menu text that the player will interact with					//NOTE: may change to a button
	int minimumSize, maximumSize;				//Minimum / Maximum size of the menu item used for resizing
	public string sceneToLoad;					//Public scene to load so that it can be changed at edit time
	bool mouseIsOver = false;					//Determines if the mouse is over the menu item
	Vector3 pos, init;							//Initialized position of the menu item and current position of the menu item
	
	public enum SlideFromWhere					//Position the menu item will slide from (made public so it can be changed at edit time)
	{
		TOP,
		LEFT,
		BOTTOM,
		RIGHT
	};
	
	public SlideFromWhere slideFromWhere = SlideFromWhere.LEFT;
	float timer;								//Timer used for time calculations
	public float slideInTime = 1;				//Time it takes to slide to the menu items destination
	
	//Use this for initialization
	void Start ()
	{
		menuItem = gameObject.guiText;			//Menu item				//NOTE: May end up becoming a button
		minimumSize = menuItem.fontSize;		//Get the size of the menu item
		maximumSize = minimumSize * 2;			//Set the maximum font size for resizing later
		pos = menuItem.transform.position;		//Initialize the menu items position
		init = menuItem.transform.position;
		
		switch(slideFromWhere)					//Checks which side the menu item will originate from
		{
			case SlideFromWhere.TOP:
			{
				init.y += 1;
				break;
			}
			case SlideFromWhere.LEFT:
			{
				init.x -= 1;
				break;
			}
			case SlideFromWhere.BOTTOM:
			{
				init.y -= 1;
				break;
			}
			case SlideFromWhere.RIGHT:
			{
				init.x += 1;
				break;
			}
		}
		timer = 0;
	}
	
	//Occurs when the mouse position is over the menu item
	void OnMouseOver()
	{
		mouseIsOver = true;
		menuItem.fontSize = maximumSize;		//Sets the font size bigger			//NOTE: May change if menu item changes
	}
	
	//Occurs when the mouse position is over the menu item and than exits
	void OnMouseExit()
	{
		mouseIsOver = false;
		menuItem.fontSize = minimumSize;		//Sets the font size smaller		//NOTE: May change if menu item changes
	}
	
	// Update is called once per frame
	void Update ()
	{
		if(timer < slideInTime)
		{
			timer += Time.deltaTime;			//Timer will be set to the time that has elapsed
			
			if(timer > slideInTime)
			{
				timer = slideInTime;
			}
			
			//Change in position for the menu item
			menuItem.transform.position = Vector3.Lerp(init, pos, timer / slideInTime);
		}
		
		if(Input.GetButtonDown("Fire1") && mouseIsOver)
		{
			if(sceneToLoad != null)
			{
				Application.LoadLevel(sceneToLoad);
			}
		}
	}
}
